﻿/************************************************
*
* Copyright(c) ZeeGuo.com
*
* CLR : 4.0.30319.296
*
* FileName : Entity7k7kComicBookList.cs
*
* Author : Kurodo
*
* CreatTime : 2013/7/18 15:49:06
*           
*************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using ComicSpider.Model;
using HtmlAgilityPack;

namespace ComicSite
{
    public class Entity7k7kComicBookList : EntityComicBookList
    {
        protected override string GetWebSiteUrl()
        {
            return "http://manhua.7k7k.com";
        }

        protected override string GetKeyCode(string context)
        {
            return "";
        }

        protected override string GetAuthor(string context)
        {
            return DataMatch.RegexsValue(context, "<p><span>原著作者：</span>(\\w{1,10})</p>", 1);
        }

        protected override string GetAddress(string context)
        {
            return DataMatch.RegexsValue(context, "<p><span>漫画区域：</span><a href=\"/search/([\\w{1,10}-]*)/\" target=\"_blank\">(\\w{1,10})</a>", 2);
        }

        protected override string GetState(string context)
        {
            return DataMatch.RegexsValue(context,"<p><span>漫画状态：</span><a href=\"/search/([\\w{1,10}-]*)/\" target=\"_blank\">([\\w{1,10}\\s]*)</a></p>", 2);
        }

        protected override string GetSubject(string context)
        {
            return DataMatch.RegexsValue(context, "<p><span>漫画类型：</span><a id=\"classdh\" href=\"http://manhua.7k7k.com/search/([\\w{1,10}-]*)/\" target=\"_blank\">\\w{1,10}</a></p>", 2);
        }

        protected override string GetCategory(string context)
        {
            return DataMatch.RegexsValue(context, "<p><span>漫画类型：</span><a id=\"classdh\" href=\"http://manhua.7k7k.com/search/([\\w{1,10}-]*)/\" target=\"_blank\">\\w{1,10}</a></p>", 2);
        }

        protected override string GetUpdate(string context)
        {
            return DataMatch.RegexsValue(context,"<p><span>更新时间：</span>(\\d{4}-\\d{2}-\\d{2})</p>", 1);
        }

        protected override string GetHotNum(string context)
        {
            return "0";
        }

        protected override string GetBookName(string context)
        {
            return DataMatch.RegexsValue(context, "<h1><a href=\"/manhua/(\\w{1,10}).html\">(\\w{1,50})</a></h1>", 2);
        }

        protected override string GetOldName(string context)
        {
            return "";
        }

        protected override string GetOtherName(string context)
        {
            return "";
        }

        public override List<EntityComicBook> GetComicList(string context)
        {
            List<EntityComicBook> list = new List<EntityComicBook>();
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(context);

            HtmlNode html = doc.DocumentNode;
            HtmlNodeCollection books = html.SelectNodes("//ul[@class='mh-directory-list']//a[@href]");
            if (books != null)
            {
                foreach (HtmlNode link in books)
                {
                    HtmlAttribute att = link.Attributes["href"];
                    Entity7k7kComicBook comics = new Entity7k7kComicBook();
                    comics.UrlAddress = string.Format("{0}{1}", this.Comic_WebSiteUrl, att.Value);
                    comics.Comic_BookName = link.InnerText;
                    list.Add(comics);
                }
            }

            return list;
        }
    }
}
